﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

public class ObjectData : BaseObject
{
    protected string _objKey;
    protected ObjectData _parent;
    private BindManage _bindManage;

    public BaseObject ProertyNames = new BaseObject();

    public BaseObject ProertyTypes = new BaseObject();

    public ObjectData(ObjectData parent, string objKey)
    {
        _parent = parent;
        _objKey = objKey;
        _bindManage = BindManage.getInstance();
    }

    public ObjectData parent
    {
        get { return _parent; }
        set { _parent = value; }
    }

    public string ObjKey
    {
        get { return _objKey; }
    }

    public object GetPropertiesEx(string PropertiesName)
    {
        if (!CheckProperties(PropertiesName))
        {
            Console.WriteLine("{0}属性不存在", PropertiesName);
        }
        return base.GetProperties(PropertiesName);
    }

    virtual public void HandlePropertiesEx(string PropertiesName, object PropertiesValue)
    {
        base.HandleProperties(PropertiesName, PropertiesValue);
    }

    public void UpdataPropertiesEx(string PropertiesName, object PropertiesValue)
    {
        base.HandleProperties(PropertiesName, PropertiesValue);
        //_bindManage.CallView(this as View,PropertiesName,PropertiesValue,true,true);

    }

    virtual public void DeletePropertiesEx(string PropertiesName)
    {
        if (CheckProperties(PropertiesName))
        {
            object PropertiesValue = GetProperties(PropertiesName);
            base.DeleteProperties(PropertiesName);
        }
    }



    /// <summary>
    /// 根据数据流缓存本地数据
    /// </summary>
    /// <param name="count">服务端属性个数</param>
    /// <param name="msg">服务端属性数据</param>
    public void setPropertiesFormByteArrayEx(int count, ByteArrayEx msg)
    {
        for (int i = 0; i < count; i++)
        {
            int index = msg.readUnsignedShort();
            string proName = (string)ProertyNames.GetProperties(index.ToString());//表名_index
            object valData = (object)msg.GetDataByType((uint)ProertyTypes.GetProperties(index.ToString()));//表名_index
            HandlePropertiesEx(proName, valData);
        }
    }

}
